home *** CD-ROM | disk | FTP | other *** search
/ Programming a Multiplayer FPS in DirectX / Programming a Multiplayer FPS in DirectX (Companion CD).iso / Source / Chapter 8 / Engine / BoundingVolume.h < prev    next >
Encoding:
C/C++ Source or Header  |  2004-10-01  |  2.8 KB  |  64 lines

  1. //-----------------------------------------------------------------------------
  2. // Used for storing a bounding volume in terms of a bounding box and a bounding
  3. // sphere. Additionally, the bounding sphere can be viewed as a 3D ellipsoid.
  4. //
  5. // Programming a Multiplayer First Person Shooter in DirectX
  6. // Copyright (c) 2004 Vaughan Young
  7. //-----------------------------------------------------------------------------
  8. #ifndef BOUNDING_VOLUME_H
  9. #define BOUNDING_VOLUME_H
  10.  
  11. //-----------------------------------------------------------------------------
  12. // Bounding Box Structure
  13. //-----------------------------------------------------------------------------
  14. struct BoundingBox
  15. {
  16.     D3DXVECTOR3 min; // Minimum extent of the bounding box.
  17.     D3DXVECTOR3 max; // Maximum extent of the bounding box.
  18.     float halfSize; // Distance from the centre of the volume to the furthest point on any axis.
  19. };
  20.  
  21. //-----------------------------------------------------------------------------
  22. // Bounding Sphere Structure
  23. //-----------------------------------------------------------------------------
  24. struct BoundingSphere
  25. {
  26.     D3DXVECTOR3 centre; // Centre point of the bounding sphere.
  27.     float radius; // Radius of the bounding sphere.
  28. };
  29.  
  30. //-----------------------------------------------------------------------------
  31. // Bounding Volume Class
  32. //-----------------------------------------------------------------------------
  33. class BoundingVolume
  34. {
  35. public:
  36.     BoundingVolume();
  37.     virtual ~BoundingVolume();
  38.  
  39.     void BoundingVolumeFromMesh( ID3DXMesh *mesh, D3DXVECTOR3 ellipsoidRadius = D3DXVECTOR3( 1.0f, 1.0f, 1.0f ) );
  40.     void BoundingVolumeFromVertices( D3DXVECTOR3 *vertices, unsigned long totalVertices, unsigned long vertexStride, D3DXVECTOR3 ellipsoidRadius = D3DXVECTOR3( 1.0f, 1.0f, 1.0f ) );
  41.     void CloneBoundingVolume( BoundingBox *box, BoundingSphere *sphere, D3DXVECTOR3 ellipsoidRadius = D3DXVECTOR3( 1.0f, 1.0f, 1.0f ) );
  42.     void RepositionBoundingVolume( D3DXMATRIX *location );
  43.  
  44.     void SetBoundingBox( D3DXVECTOR3 min, D3DXVECTOR3 max );
  45.     BoundingBox *GetBoundingBox();
  46.  
  47.     void SetBoundingSphere( D3DXVECTOR3 centre, float radius, D3DXVECTOR3 ellipsoidRadius = D3DXVECTOR3( 1.0f, 1.0f, 1.0f ) );
  48.     BoundingSphere *GetBoundingSphere();
  49.  
  50.     void SetEllipsoidRadius( D3DXVECTOR3 ellipsoidRadius );
  51.     D3DXVECTOR3 GetEllipsoidRadius();
  52.  
  53. private:
  54.     BoundingBox *m_box; // Box representation of the bounding volume.
  55.     BoundingSphere *m_sphere; // Sphere representation of the bounding volume.
  56.  
  57.     D3DXVECTOR3 m_originalMin; // Original minimum extents of the bounding box.
  58.     D3DXVECTOR3 m_originalMax; // Original maximum extents of the bounding box.
  59.     D3DXVECTOR3 m_originalCentre; // Original centre point of the bounding sphere.
  60.  
  61.     D3DXVECTOR3 m_ellipsoidRadius; // Ellipsoid radius (i.e. the radius along each axis).
  62. };
  63.  
  64. #endif